package com.elhakimz.matra.battle;

import com.elhakimz.matra.actor.Actor;
import com.elhakimz.matra.pattern.ISignalSlot;
import com.elhakimz.matra.pattern.SignalType;

import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: abiel
 * Date: Feb 18, 2010
 * Time: 2:45:09 PM
 * To change this template use File | Settings | File Templates.
 */
public class BattleManager implements ISignalSlot {

    public static final String FACTION_BLUE="blue";
    public static final String FACTION_RED="red";
    public static final String FACTION_GREEN="green";


    public static final String ACTOR_ACTIVE="ACTIVE";
    public static final String ACTOR_KILLED="KILLED";


    private HashMap tracks;

    public BattleManager() {
        this.tracks = new HashMap();
    }


    public void signal(SignalType signal) {

        if(signal.type.equals(SignalType.SIG_TYPE_RESPONSE)){

           if(signal.sign.equals(ACTOR_ACTIVE) &&(signal.sender instanceof Actor)){
             registerTrack((Actor) signal.sender);
           }else if(signal.sign.equals(ACTOR_KILLED) &&(signal.sender instanceof Actor)){
              destroyTrack(((Actor)signal.sender).getName());  
            }
        }
    }

    /**
     * register an actor to battle manager
     * @param track
     */
    private void registerTrack(Actor track){
        tracks.put(track.getName(),track);
        System.out.println("BM:TRACK REGISTERED");

    }

    /**
     * destroy actor in registry
     * @param name
     */
    private void destroyTrack(String name){
        tracks.put(name,null);
        System.out.println("BM:TRACK DESTROYED");


    }

}
